package com.ichart.html;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import com.ichart.doc.Component;
import com.ichart.doc.ComponentUtils;
import com.ichart.doc.Info;

public class ReferenceTemplate extends Template<List<Component>> {

	public ReferenceTemplate(){
		//this.theme.setJs(new String[]{"../js/jquery-1.7.2.min.js"});
	}
	
	@Override
	protected void detail() {
		String name = "";
		html.append("<div class='ichartjs_home'>");
		html.append(Info.info("AllClass"));
		
		html.append("<a href=\"home.html\" target=\"main\" >");
		html.append(Info.info("Charts"));
		html.append("</a>");
		html.enter("</div>");
		
		Collections.sort(this.object,new Comparator<Component>(){
		@Override
		public int compare(Component cc1, Component cc2) {
			    int length1 = cc1.getClassName().length();   
			    int length2 = cc2.getClassName().length();   
			    String o1 = cc1.getClassName().toLowerCase();
			    String o2 = cc2.getClassName().toLowerCase();
			    int length = length1 > length2 ? length2 : length1;   
			    int c1, c2;   
			    for (int i = 0; i < length; i++) {   
			      c1 = o1.charAt(i);   
			      c2 = o2.charAt(i);   
			      if (c1 > c2) {   
			        return 1;   
			      }else if(c1 < c2) {   
			        return -1;   
			      }  
			    }   
			    if (length1 > length2) {   
			      return 1;   
			    } else if (length1 < length2) {   
			      return -1;   
			    }
			    return 0;   
		}});
		
		for (Component component : this.object) {
			name = component.getName();
			html.append("<div class='ichartjs_menu'");
			html.append(" onmouseover='this.style.backgroundColor=\"#eeeeee\"' ");
			html.append(" onmouseout='this.style.backgroundColor=\"#dfe6e4\"' ");
			html.enter(">");
			html.append(ComponentUtils.getLink(name));
			html.enter("</div>");
		}
	}

	@Override
	protected String page() {
		Html html = new Html();
		html.enter("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
		html.enter("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
		html.enter("<head>");
		html.enter("<title>iChartJS API</title>");
		html.enter(this.theme);
		html.enter("</head>");
		html.enter("<body class='ichartjs_page'>");
		html.enter(this.html.toString());
		html.append("</html>");
		return html.toString();
	}

	@Override
	protected void reference() {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected void summary() {
		// TODO Auto-generated method stub
		
	}
	
	

	
	

	
		
}
